import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

// 避免用户重复点击 重复调用push  replace 方法 而产生的错误日志
const originalPush = Router.prototype.push;
Router.prototype.push = function (location) {
    return originalPush.call(this, location).catch(err => { })
};

export default new Router({
    routes: [
        {
            path: '/',
            redirect: '/dashboard'
        },
        {
            path: '/',
            component: () => import('../components/common/Home.vue'),
            meta: { title: '主页' },
            children: [
                {
                    path: '/dashboard',
                    component: () => import('../components/page/Dashboard.vue'),
                    meta: { title: '系统首页' }
                },
                {
                    path: '/onlineexam',
                    component: () => import('../components/page/OnlineExam.vue'),
                    meta: { title: '在线考试' }
                },
                {
                    path: '/readyexam',
                    component: () => import('../components/page/Readyexam.vue'),
                    meta: { title: '准备考试' }
                },
                {
                    path: '/examination',
                    component: () => import('../components/page/Examination.vue'),
                    meta: { title: '正在考试' }
                },
                {
                    path: '/mygrades',
                    component: () => import('../components/page/MyGrades.vue'),
                    meta: { title: '我的成绩' }
                },
                {
                    path: '/topiclibmanagement',
                    component: () => import('../components/page/TopicLibManagement.vue'),
                    meta: { title: '题库管理' }
                },
                {
                    path: '/mytopicmanagement',
                    component: () => import('../components/page/MyTopicManagement.vue'),
                    meta: { title: '试题管理' }
                },
                {
                    path: '/examinationmanagement',
                    component: () => import('../components/page/ExaminationManagement.vue'),
                    meta: { title: '考试管理' }
                },
                {
                    path: '/usermanagement',
                    component: () => import('../components/page/UserManagement.vue'),
                    meta: { title: '用户管理' }
                },
                {
                    // 我的成绩详情
                    path: '/answer',
                    component: () => import('../components/page/Answer.vue'),
                    meta: { title: '我的答题' }
                },
                {
                    path: '/404',
                    component: () => import('../components/page/404.vue'),
                    meta: { title: '404' }
                },
                {
                    path: '/403',
                    component: () => import('../components/page/403.vue'),
                    meta: { title: '403' }
                },
            ]
        },
        {
            path: '/login',
            component: () => import('../components/page/Login.vue'),
            meta: { title: '登录' }
        },
        {
            path: '/register',
            component: () => import('../components/page/Register.vue'),
            meta: { title: '注册' }
        },
        {
            path: '*',
            redirect: '/404'
        }
    ]
});
